package com.changyinBus.web.core.config;

import com.alibaba.fastjson2.JSONObject;
import com.changyinBus.common.constant.CacheConstants;
import com.changyinBus.common.utils.CookieUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class GlobalModelAndViewInterceptor implements HandlerInterceptor {


    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        //获取站点信息
        long tenantId = CookieUtils.getCookieByLong(request, "tenantId");
        if (tenantId == 0) {
            //没有站点信息默认中文
            tenantId = 1;
            CookieUtils.setCookie(response, "tenantId", String.valueOf(tenantId), (int) CacheConstants.MILLIS_MINUTE);
        }
        if (modelAndView != null) {
            modelAndView.addObject("site", "");
        }
    }
}
